window.onload = function () {
    var writeview = document.querySelector('.writeview')
    var exampleInputtitle = document.querySelector('#exampleInputtitle')
    var textinput = document.querySelector('#textinput')
    var btndefault = document.querySelector('.btn-default')
    // 截取参数
    var parms = location.search.substring(1);
    // console.log(location.search);
    var arr = parms.split('=');
    const id = arr[1]
    btndefault.onclick = function () {
        if (exampleInputtitle.value != '' && textinput.value != '') {
            $.ajax({
                type: 'post',
                url: 'http://127.0.0.1:3007/api/write',
                dataType: 'json',
                data: {
                    title: exampleInputtitle.value,
                    text: textinput.value,
                    uid: id
                },
                success: function (res) {
                    window.location.href = "index.html?id=" + res.id;
                }
            })
            console.log(exampleInputtitle.value, textinput.value);

        } else {
            alert('标题或文章不能为空')
        }
    }
}